import 'dart:async';
import 'dart:io';

import 'package:core/core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'my_app.dart';
import 'config.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await localInit();
  await networkInit();

  //沉浸式
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }

  //竖屏 禁止旋转屏幕
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((
    value,
  ) {
    //发布版本 捕捉异常
    // if (AppConfig.isRelease) {
    //   //会报Zone mismatch异常
    //   // FlutterBugly.postCatchedException(
    //   //       () => runApp(const MyApp()),
    //   //   debugUpload: true,
    //   //   filterRegExp: "Zone mismatch",
    //   // );
    // } else {
    runApp(const MyApp());
    // }
  });
}

//本地初始化
Future localInit() async {
  await StorageManager.init();
  await SpUtil.getInstance();
  await AppConfig.init(app);
  LogUtil.init(isDebug: !AppConfig.isRelease, tag: "cinema");
  ExceptionHelper.init(
    isDebug: !AppConfig.isRelease,
    noNetworkLinkTips: '网络连接不可用,请稍后重试',
    exceptionTips: '网络繁忙,请稍后再试',
  );
}

//需要网络的初始化
Future<void> networkInit() async {}
